import React from 'react'

// 导入连接store的方法
import {connect} from 'react-redux';

class Total extends React.Component {
  render() {
    // console.log('接收state的数据：',this.props)
    const {total} = this.props;
  return <div>商品总数：【{total}】</div>
  }
}


const mapStateToProps = (state, ownProps)=>{
  // console.log(state, ownProps)
  return {
     total: Object.values(state).reduce((p,n)=>p+n)
  }
}

// 连接store,获取共享的数据state
const NewTotal = connect(mapStateToProps)(Total)

export default NewTotal
